package com.demo.designmode.flyweight;

import java.util.HashMap;

/**
 * @Author: jxm
 * @Description: 工厂类。为单例
 * @Date: 2023-11-17 15:08
 * @Version: 1.0
 */
public class BoxFactory {

    private static HashMap<String, AbstractBox> map;

    private BoxFactory() {
        map = new HashMap<String, AbstractBox>();
        AbstractBox iBox = new IBox();
        AbstractBox lBox = new LBox();
        AbstractBox oBox = new OBox();
        map.put("I", iBox);
        map.put("L", lBox);
        map.put("O", oBox);
    }

    //静态内部类
    public static class SingletonHolder{
        private static final BoxFactory INSTANCE = new BoxFactory();
    }

    public static BoxFactory getInstance(){
        return SingletonHolder.INSTANCE;
    }

    //根据名称获取图形对象
    public AbstractBox getBox(String key) {
        return map.get(key);
    }
}
